﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;

namespace Portfolio_Tracker
{
    public partial class NewsForm : Form
    {
        // Constructor
        public NewsForm(List<System.Xml.Linq.XElement> dates, List<System.Xml.Linq.XElement> titles, List<System.Xml.Linq.XElement> links)
        {
            InitializeComponent();

            for (int i = 0; i < dates.Count(); i++)
            {
                newsDataGridView.Rows.Add(dates[i].ToString().Substring(9, dates[i].ToString().Length - 19), titles[i].ToString().Substring(7, titles[i].ToString().Length - 15), links[i].ToString().Substring(6, links[i].ToString().Length - 13));
            }   
        }

        // News DataGridView Cell Click Event
        private void newsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                DialogResult dr = MessageBox.Show("You are being taken to a news article, proceed?", "Venture At Your Own Risk", MessageBoxButtons.YesNo);

                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(newsDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString());
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }
        }
    }
}
